// <Switch>
// <Route path component>
// </Switch>
import {Suspense} from 'react'
import { Switch,Route,Redirect  } from "react-router-dom";


function RouterView(props){
    var token = true
    var roules = props.roules
    return <Switch>
        <Suspense fallback="<h2>加载中</h2>">
        {
            roules.map((item,index)=>{

                if(!token && item.path !== "/index"){
                    return <Redirect key={index} to="/login"></Redirect>
                }
                if(item.component){
                    return <Route key={index} exact={item.exact} path={item.path} component={item.component}></Route>
                }//如果有item.component，证明是常规路由，否则可能是跳转
                else{
                    return <Route key={index} exact={item.exact} path={item.path}>
                        <Redirect to={item.redirect}></Redirect>
                    </Route>
                }
            })
        }
        </Suspense>
    </Switch>
}

export default RouterView
